Routines (alphabetical) > Routines: C > CDF Routines > CDF_COMPRESSION

CDF_COMPRESSION

The CDF_COMPRESSION procedure sets or returns the compression mode for a CDF file and/or variables. Compression parameters should be set before values are written to the CDF file.

Special Note About Temporary File Location

CDF creates temporary files whenever files/variables are compressed or uncompressed. By default, these files are created in the current directory. UNIX users can set the environment variable CDF_TMP to set the temporary directory explicitly.

Syntax

CDF_COMPRESSION, Id [, GET_COMPRESSION =variable] [, GET_GZIP_LEVEL =variable] [, GET_VAR_COMPRESSION =variable] [, GET_VAR_GZIP_LEVEL =variable] [, SET_COMPRESSION ={0 | 1 | 2 | 3 | 5}] [, SET_GZIP_LEVEL =integer{1 to 9}] [, SET_VAR_COMPRESSION ={0 | 1 | 2 | 3 | 5}] [, SET_VAR_GZIP_LEVEL =integer{1 to 9}]
[, VARIABLE =variable name or index] [, /ZVARIABLE ]

Arguments

Id

The CDF ID of the file being compressed or queried, as returned from a previous call to CDF_OPEN or CDF_CREATE. Note that CDF compression only works for single-file CDF files (see CDF_CREATE).

Keywords

GET_COMPRESSION

Set this keyword to a named variable to retrieve the compression type used for the single-file CDF file. Note that individual CDF variables may compression types different that the one for the rest of the CDF file.

GET_GZIP_LEVEL

Set this keyword to a named variable in which the current GZIP effort level (1-9) for the CDF file is returned. If the compression type for the file is not GZIP (5), then a value of zero is returned.

GET_VAR_COMPRESSION

Set this keyword to a named variable to retrieve the compression type for the variable identified by the VARIABLE keyword.

GET_VAR_GZIP_LEVEL

Set this keyword to a named variable in which the GZIP effort level (1-9) for variable specified by the VARIABLE keyword is returned. If the compression type for the variable is not GZIP (5), then a value of zero is returned.

SET_COMPRESSION

Set this keyword to the compression type to be used for the single-file CDF file. Note that individual CDF variables may use compression types different than the one for the rest of the CDF file. Valid compression types are:

SET_GZIP_LEVEL

This keyword is used to indicate the desired effort for the GZIP compression. This effort must be expressed as a scalar in the range (1-9). If GZIP_LEVEL is not specified upon entry then the default effort level is taken to be 5. If the SET_GZIP_LEVEL keyword is set to a valid value, and the keyword SET_COMPRESSION is not specified, the SET_COMPRESSION is set to GZIP (5).

SET_VAR_COMPRESSION

Set this keyword to the compression type for the variable identified by the VARIABLE keyword. If the variable is a zVariable, and is referred to by index in the VARIABLE keyword, then the keyword ZVARIABLE must be set. The desired variable compression should be set before variable data is added with CDF_VARPUT. Valid compression types are:

SET_VAR_GZIP_LEVEL

Set this keyword to the GZIP effort level (1-9). If the compression type for the variable is not GZIP (5), no action is performed.

VARIABLE

Set this keyword to the name of a variable or a variable index to set the current variable. This keyword is mandatory when queering/setting the compression parameters of a rVariable or zVariable. Note that if VARIABLE is set to the index of a zVARIABLE, the ZVARIABLE keyword must also be set. If ZVARIABLE is not set, the variable is assumed to be an rVariable.

ZVARIABLE

Set this keyword if the current variable is a zVARIABLE and is referred to by index in the VARIABLE keyword. For example:

CDF_COMPRESSION, id, VARIABLE=0, /ZVARIABLE,$    GET_VAR_COMPRESSION=vComp

Examples

; Create a CDF file and define the compression.

; Compression only works on Single-File CDFs:

id=CDF_CREATE('demo.cdf',[10,20],/CLOBBER,/SINGLE_FILE)

CDF_COMPRESSION,id,SET_COMPRESSION=1 ; (Run-length encoding)

att_id=CDF_ATTCREATE(id, 'Date',/GLOBAL)

CDF_ATTPUT,id,'Date',att_id,systime()

 

; Change the compression type for the file to GZIP by using

; SET_GZIP_LEVEL:

CDF_COMPRESSION,id,SET_GZIP_LEVEL=7

 

; Retrieve compression information:

CDF_COMPRESSION,id,GET_GZIP_LEVEL=glevel,GET_COMPRESSION=gcomp

HELP,glevel,gcomp

 

; Create and compress an rVariable:

rid=CDF_VARCREATE(id,'rvar0',[1,1],/CDF_FLOAT)

CDF_COMPRESSION,id,SET_VAR_COMPRESSION=2,VARIABLE='rvar0'

CDF_VARPUT,id,'rvar0',findgen(10,20,5)

CDF_COMPRESSION,id,GET_VAR_COMPRESSION=v_comp,VARIABLE=rid,GET_VAR_GZIP_LEVEL=v_glevel

HELP,v_comp,v_glevel

 

; Create and compress a zVariable:

zid=CDF_varcreate(id,'zvar0',[1,1,1],DIM=[10,20,30],/ZVARIABLE,$

   /CDF_DOUBLE)

 

; You can set a compression and check it in the same call:

CDF_COMPRESSION,id,SET_VAR_GZIP_LEVEL=9,VARIABLE=zid,/ZVARIABLE,$

   GET_VAR_GZIP_LEVEL=v_gzip

HELP,v_gzip

 

CDF_VARPUT,id,zid,dindgen(10,20,30),/ZVARIABLE

 

; File and variable keywords can be combined in the same call

; (Set calls are processed before Get calls)

CDF_COMPRESSION,id,GET_VAR_COMPRESSION=v_comp,VARIABLE='zvar0',$

   /ZVARIABLE, SET_COMPRESSION=2,GET_COMPRESSION=file_comp

HELP,file_comp,v_comp

 

CDF_DELETE,id

IDL Output

GLEVEL LONG = 7

GCOMP LONG = 5

 

V_COMP LONG = 2

V_GLEVEL LONG = 0

 

(Note that V_GLEVEL is 0, since the variable compression is not GZIP.)

V_GZIP LONG = 9

 

FILE_COMP LONG = 2

V_COMP LONG = 5

Version History

 

5.3

Introduced

See Also

CDF_CONTROL, CDF_CREATE, CDF_OPEN, CDF_VARNUM